def getPowerDigit(index, power):
    power_list = [
        ["I", "V", "X"],
        ["X", "L", "C"],
        ["C", "D", "M"],
        ["M",]
    ];
    return power_list[power][index];

def getDigits(num, power):
    if num - 5 > 3: # num => [9]
        return getPowerDigit(0, power) * (10 - num) + getPowerDigit(2, power);
    elif num - 5 > 0: # num => [6, 8]
        return getPowerDigit(1, power) + getPowerDigit(0, power) * (num - 5);
    elif num - 5 > -2: # num => [4, 5]
        return getPowerDigit(0, power) * (5 - num) + getPowerDigit(1, power);
    else: # num => [0, 3]
        return getPowerDigit(0, power) * num;

def convert(num):
    """

    convert num > 0 and <= 3999 to Roman digits

    :type num: int
    :rtype str
    """
    if num < 1 or num > 3999:
        print('Num should between 1 and 3999');
        return num;

    roman = [];
    roman.append(getDigits(num // 1000 % 10, 3));
    roman.append(getDigits(num // 100 % 10, 2));
    roman.append(getDigits(num // 10 % 10, 1));
    roman.append(getDigits(num % 10, 0));
    return ''.join(roman);

def convert2(num):
    if num < 1 or num > 3999:
        print('Num should between 1 and 3999');
        return num;
    roman_list = [
        ["","I","II","III","IV","V","VI","VII","VIII","IX"],
        ["","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"],
        ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"],
        ["","M","MM","MMM"]
    ];
    roman = [];
    roman.append(roman_list[3][num // 1000 % 10]);
    roman.append(roman_list[2][num // 100 % 10]);
    roman.append(roman_list[1][num // 10 % 10]);
    roman.append(roman_list[0][num % 10]);
    return ''.join(roman);
